package com.util;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

import com.bean.CityGoCount;
import com.bean.CountryGoCount;
import com.bean.UserList;
import com.bean.UserLogin;

@Component("avatarUtil")
public class AvatarUtil {

	@Autowired
	private MongoTemplate mongoTemplate;
	
	/*public List<Contentmanages> setContentmanagesAvatar(List<Contentmanages> contentmanagess){
		for(Contentmanages contentmanages:contentmanagess){
			String avatar=getAvatar(contentmanages.getWeiboid());
			contentmanages.setAvatar(avatar);
			String text_type=contentmanages.getText_type();
			if(text_type==null||text_type.equals("")){
				contentmanages.setText_type(Domain.text_type_pic);
			}
		}
		return contentmanagess;
	}*/
	
	public  String getAvatar(String userId){
		UserList userList=mongoTemplate.findById(userId, UserList.class);
		String avatar=null;
		if(userList!=null){
			avatar=userList.getUrl();
		}
		return avatar;
	}
/*	public List<ArticleSave> setArticleSaveAvatar(List<ArticleSave> articleSaves){
		for(ArticleSave articleSave:articleSaves){
			String avatar=getAvatar(articleSave.getWeiboid());
			articleSave.setAvatar(avatar);
		}
		return articleSaves;
	}
	public List<VideoSave> setVideoSaveAvatar(List<VideoSave> videoSaves){
		for(VideoSave videoSave:videoSaves){
			String avatar=getAvatar(videoSave.getWeiboid());
			videoSave.setAvatar(avatar);
		}
		return videoSaves;
	}*/
	public List<CityGoCount> setStarCountAvatar(List<CityGoCount> cityGoCounts,Map<String, String> map){
		//UserLogin userLogin=mongoTemplate.findById(userId, UserLogin.class);
		for(CityGoCount cityGoCount:cityGoCounts){
			cityGoCount.setImages(map.get(cityGoCount.getId()));
		}
		return cityGoCounts;
	}
	public CityGoCount setStarCountAvatar(CityGoCount starGoCount,Map<String, String> map){
		starGoCount.setImages(map.get(starGoCount.getId()));
		return starGoCount;
	}
	
	public List<CountryGoCount> setCountryCountAvatar(List<CountryGoCount> countryGoCounts,Map<String, String> map){
		for(CountryGoCount countryGoCount:countryGoCounts){
			countryGoCount.setImages(map.get(countryGoCount.getId()));
		}
		return countryGoCounts;
	}
	
	public  String getUserLoginAvatar(String user_id){
		UserLogin userLogin=mongoTemplate.findById(user_id, UserLogin.class);
		String avatar=null;
		if(userLogin!=null){
			avatar=userLogin.getAvator_url();
		}
		return avatar;
	}
/*	public List<UserOrgInfo> setUserOrgInfoAvatar(List<UserOrgInfo> data){
		for(UserOrgInfo userOrgInfo:data){
			for(com.bean.UserOrgInfo.UserInfo userinfo:userOrgInfo.getUserInfo()){
				String avatar=getAvatar(userinfo.getWeiboid());
				userinfo.setAvatar(avatar);
			}
		}
		return data;
	}*/
	
	/*public NewFan setNewFanAvatar(NewFan newFan){
		for(Fans fans:newFan.getFans()){
			UserLogin userLogin=mongoTemplate.findOne(new Query(Criteria.where("id").is(fans.getUserId())), UserLogin.class);
			String avatar=null;
			String nickname=null;
			//int fensiNum=0;
			int guanzhuNum=0;
			if(userLogin!=null){
				avatar=userLogin.getAvator_url();
				nickname=userLogin.getNickname();
				
				if(userLogin.getFollow()!=null&&!userLogin.getFollow()[0].equals("")){
					guanzhuNum=guanzhuNum+userLogin.getFollow().length;
				}
				if(userLogin.getOwnFollow()!=null&&!userLogin.getOwnFollow()[0].equals("")){
					guanzhuNum=guanzhuNum+userLogin.getOwnFollow().length;
				}
				
				//long count =mongoTemplate.count(new Query(Criteria.where("ownFollow").in(userLogin.getId())), UserLogin.class);
				//fensiNum=Integer.valueOf(String.valueOf(count));
			}
			fans.setAvatar(avatar);
			//fans.setFensiNum(fensiNum);
			//fans.setGuanzhuNum(guanzhuNum);
			fans.setNickname(nickname);
		}
		
		return newFan;
	}*/
	public static void main(String[] args) {
		String [] arr={
				"tt","aa"
		};
			
		System.err.println(Arrays.asList(arr).contains("tt"));
	}
}
